import React, { useReducer } from 'react'

export default function App() {
  const reducer = (state, { type, payload }) => {
    if (type === 'increment') {
      return {
        ...state,
        count: state.count + payload
      }
    } else {
      return state
    }
  }

  const [state, dispatch] = useReducer(reducer, { count: 100 })

  const handleIncrement = () => {
    console.log(1)
    dispatch({
      type: 'increment',
      payload: 2
    })
  }

  return (
    <div>
      <h1>当前计数为：{state.count}</h1>
      <button onClick={handleIncrement}>+</button>
    </div>
  )
}
